#!/usr/bin/env python

# Imports
from GameUI import *
from GameMap import *
from Creature import *
from Player import *
from Npc import *
import random

def main ():
    objects = []
    game = GameUI()
    ticker = Ticker()
    map = gameMap(15, 30, game, objects)

    map.genMap()

    map.drawMap()

    pc = Player(game, map, objects, 5, map.width - 3, '@', ticker, 3, True, 1, 100)
    objects.append(pc)

    for i in range(random.randint(10, 50)):
        y, x, = 0, 0
        while map.map[y][x].walkable == False or x > map.width-4:
            y, x = random.randint(0, map.height-1), random.randint(0, map.width-1)

        npc = Npc(game, map, objects, y, x, "m", ticker, 4, False, random.randint(1, 10), random.randint(1, 5))
        objects.append(npc)

    while pc.running == True:
        pc.fov.computeFov()
        map.drawMap()
        ticker.ticks += 1
        ticker.nextTurn()
        game.putString(map.height+1, 0, str(ticker.ticks), 7)
        game.clearLine(map.height)
        game.putString(map.height, 0, str(game.key), 3)
        game.clearLine(map.height+3)
        game.putString(map.height+3, 0, str(pc.health), 3)

        if pc.trees_chopped == map.trees:
            game.clearLine(map.height+2)
            game.putString(map.height+2, 0, "You chopped down all trees! You Win!", 7, True)
            game.getKey(True)
            pc.running = False
        if len(objects) == 1:
            game.clearLine(map.height+2)
            game.putString(map.height+2, 0, "You killed all monkeys! You Win!", 7, True)
            game.getKey(True)
            pc.running = False
        if pc.health <= 0:
            game.clearLine(map.height+2)
            game.putString(map.height+2, 0, "You were killed! you die!", 4, True)
            game.getKey(True)
            pc.running = False

if __name__ == '__main__':
    main()
